// pages/dichan/dichan.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swipers: {
      imgs: '../images/banner.jpg',
      imgs2: '../images/banner.jpg',
      imgs3: '../images/banner.jpg',
    },

    num: 3,
    hostUrl: app.globalData.hostUrl,
    region: ['广东省', '广州市', '海珠区'],
    customItem: '全部',

    // 三联属性
    array: ['爱上对方感的地方', '中国', '巴西', '日本'],
    shiarray: ['aaa', 'bbb', 'ccc', 'bbb'],
    quarray: ['111', '222', '333', '444'],
    index: 0,
    shiindex: 0,
    quindex: 0,
    clickShow: false,
  },
  // 三联开始
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为省', e.detail.value)
    var index = e.detail.value;
    if (this.data.info['province'][index]['AreaName'] == "请选择") {
      return;
    }
    this.setData({
      index: e.detail.value
    })
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'Hotel/getarea',
      data: {
        ParentId: that.data.info['province'][index]['AreaId'],
        type: 'house'
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        // console.log(res)
        if (res.data != null) {
          that.setData({
            shiarray: res.data,
          })
        }
      }
    })
  },
  bindShiChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var shiindex = e.detail.value;
    if (this.data.shiarray[shiindex]['AreaName'] == "请选择") {
      return;
    }
    this.setData({
      shiindex: e.detail.value
    })
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'Hotel/getarea',
      data: {
        ParentId: that.data.shiarray[shiindex]['AreaId'],
        type: 'house'
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        // console.log(res)
        if (res.data != null) {
          that.setData({
            quarray: res.data,
          })
        }
      }
    })
  },
  bindQuChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var code = this.data.quarray[e.detail.value]['AreaCode'];
    if (this.data.quarray[e.detail.value]['AreaName'] == "请选择") {
      return;
    }
    this.setData({
      quindex: e.detail.value
    })
    wx.navigateTo({
      url: '../new_inter/hotel_dcils/hotel_dcils?quid=' + code,
    })
  },

  // 点击显示三联
  clickCityPicker: function() {
    this.setData({
      clickShow: true
    })
  },

  // 搜索框三联
  bindRegionChange: function(e) {
    console.log(e)

    console.log('picker发送选择改变，携带值为', e.detail.value)
    // this.setData({
    //   region: e.detail.value
    // })
    wx.navigateTo({
      url: '../new_inter/hotel_dcils/hotel_dcils?quid=' + e.detail.code[2],
    })
  },
  lvyou_dichan: function(typeId) { //读取首页banner
    var that = this;
    wx.request({
      url: app.globalData.apiUrl + 'Index/lvyou_dichan',
      data: {
        // opt: 'getBanner',
        typeId: '',
      },
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        console.log(res)
        if (res.data != null) {
          that.setData({
            info: res.data,
          })
          var adv = res.data.adv[1];
          for (var i = 0, len = adv.length; i < len; ++i) {
            var desc = that.delHtmlTag(res.data.adv[1][i].desc)
            res.data.adv[1][i].desc = desc;
          }
          that.setData({
            info: res.data,
            array: res.data.province
          })
        }
      }
    })
    // console.log(that.data.imgBanner['0'])
  },
  delHtmlTag: function(msg) {
    var msg = msg.replace(/<\/?[^>]*>/g, ''); //去除HTML Tag
    msg = msg.replace(/[|]*\n/, '') //去除行尾空格
    msg = msg.replace(/&nbsp;/ig, ''); //去掉npsp
    return msg;
  },
  //  选项卡
  swiperTab: function(e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  clickTab: function(e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  swiperTab2: function(e) {
    var that = this;
    that.setData({
      currentTabs: e.detail.current
    });
  },
  clickTab2: function(e) {
    var that = this;
    if (this.data.currentTabs === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTabs: e.target.dataset.current
      })
    }
  },
  // 头部导航
  // nav: function (e) {
  //   console.log(e);
  //   this.setData({
  //     num: e.target.dataset.num
  //   })
  // },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.lvyou_dichan();
    this.setData({
      foot:wx.getStorageSync('foot'),
      is_show:wx.getStorageSync('is_show')

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  index: function() {
    wx.reLaunch({
      url: '../index/index'
    })
  },
  // lvju: function () {
  //   wx.reLaunch({
  //     url: '../lvju/lvju'
  //   })
  // },
  // jiankang: function () {
  //   wx.navigateTo({
  //     url: '../jiankang/jiankang'
  //   });
  // },
  // news: function () {
  //   wx.navigateTo({
  //     url: '../news/news'
  //   });
  // },
})